﻿@model IEnumerable<PotentialRentals.Models.Rental>

@if (TempData["success"] != null)
{
    @Html.Raw("<div id='response' class='success'>" + TempData["success"].ToString() + "</div>")
}
else if (TempData["failure"] != null)
{
    @Html.Raw("<div id='response' class='failure'>" + TempData["failure"].ToString() + "</div>")
}
    
<script type="text/javascript">
    $("#response").slideDown("slow").delay(5000).slideUp("slow");
</script>
    
<hr />

@if (Model.Any())
{    
    foreach (var item in Model)
    {
        <div id="user-rental" class="@item.Address.AddressId">
            <span class="rent">$@item.Rent</span>
            @if (item.Address.Name != null)
            {
                <span class="title">@item.Address.Name</span><br />
                <span class="location">@item.Address.Street<br />@item.Address.City,&nbsp;@item.Address.State.Abbr</span><br />
            }
            else
            {
                <span class="title">@item.Address.Street<br />@item.Address.City,&nbsp;@item.Address.State.Abbr</span>
            }
            <span class="bed-bath">@String.Format("{0}br/{1:0.##}ba", item.Bedrooms, item.Bathrooms)</span>
            <span class="remove">@Ajax.ActionLink("Remove from List", "Remove", new { id = item.RentalId, address = item.Address.Street, bedrooms = item.Bedrooms, bathrooms = item.Bathrooms, rent = item.Rent }, new AjaxOptions { HttpMethod = "POST", OnSuccess = "refreshLists()" })</span>
            <div id="rental-details">
                <div id="details-body">
                    <div id="details-content">
                        @if (item.Phone != null)
                        {
                            <span class="title">Phone:&nbsp;</span>
                            <span class="Phone">@item.Phone</span><br />
                        }
                        @if (item.Email != null)
                        {
                            <span class="title">Email:&nbsp;</span>
                            <span class="Email">@Html.Raw(String.Format("<a href='mailto:{0}'>{0}</a>", item.Email))</span><br />
                        }
                        @if (item.Amenities.Any() || item.Address.Amenities.Any())
                        {
                            <div class="Amenities">
                            <span class="title">Amenities:</span><br style="clear:both" />
                            @foreach (var amenity in item.Amenities)
                            {
                                @Html.Raw(amenity.Name + "<br />");
                            }
                            @foreach (var amenity in item.Address.Amenities)
                            {
                                @Html.Raw(amenity.Name + "<br />");
                            }
                            </div>
                        }
                    </div>
                    <div id="details-footer"><a href="#" onclick="$('div#rental-details').hide();">Close</a></div>
                </div>
                <div id="details-arrow"><img src="@Url.Content("~/Content/images/address-extra-arrow.png")" /></div>
            </div>
            <br style="clear:both" />
        </div>
        <hr />
    
        if (item.Address.Lat != null && item.Address.Lng != null)
        {
            <script type="text/javascript">
                //Display Details on Mouse-over
                $("#user-rental[class='@item.Address.AddressId']").hover(function() {
                    $(this).find("div#rental-details").show();
                },
                function() {
                    $("div#rental-details").hide();
                });
                $("#user-rental[class='@item.Address.AddressId']").click(function() {
                    map.setCenter(new google.maps.LatLng(@item.Address.Lat, @item.Address.Lng));
                });
    
                addMarker("@item.Address.Lat", "@item.Address.Lng", "@item.Address.Street @item.Address.City, @item.Address.State.Abbr", "@item.Address.AddressId");
            </script>
        }
    }

    <script type="text/javascript">
        map.fitBounds(bounds);
    </script>
}
else
{
    <span class="empty">No addresses in your list.</span>
}